package org.jeecg.modules.oms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.oms.entity.OmsInquiryRuleValue;
import org.jeecg.modules.oms.service.IOmsInquiryRuleValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 询单规则值管理
 */
@Api(tags = "询单规则值管理")
@RestController
@RequestMapping("/oms/omsInquiryRuleValue")
@Slf4j
public class OmsInquiryRuleValueController extends JeecgController<OmsInquiryRuleValue, IOmsInquiryRuleValueService> {

    @Autowired
    private IOmsInquiryRuleValueService inquiryRuleValueService;

    /**
     * 根据规则ID获取规则值列表
     *
     * @param ruleId 规则ID
     * @return 规则值列表
     */
    @AutoLog(value = "询单规则值-根据规则ID获取列表")
    @ApiOperation(value = "询单规则值-根据规则ID获取列表", notes = "询单规则值-根据规则ID获取列表")
    @GetMapping(value = "/listByRuleId")
    public Result<List<OmsInquiryRuleValue>> listByRuleId(@RequestParam(name = "ruleId") String ruleId) {
        try {
            QueryWrapper<OmsInquiryRuleValue> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("rule_id", ruleId);
            queryWrapper.orderByAsc("sort_no");
            List<OmsInquiryRuleValue> list = inquiryRuleValueService.list(queryWrapper);
            return Result.OK(list);
        } catch (Exception e) {
            log.error("根据规则ID获取规则值列表失败", e);
            return Result.error("获取失败：" + e.getMessage());
        }
    }
}
